<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
    <ui:define name="content">
    <h:form id="form" align="center">
    <div id="iddiv" align="center" style="width : 800px;font-size: 10pt" >
    <br />
    <p:panel id="idpanel">
    	<h:message for="inventoryId"/>
    	<f:facet name="header">
    		<h:outputText value="Find Medication By MedicationID" />
		</f:facet>
    	<h:panelGrid columns="3">
    				<h:outputText value="Medication Id: " />
        			<p:inputText value="#{inventoryBean.medicationId}" id="inventoryId" required="true" />
        			<p:commandButton action="#{inventoryBean.findInventoryById}" value="Find by Id" update="medinv" process="@this,inventoryId"/>
        			<p:spacer height="2"/><p:spacer height="2"/><p:spacer height="2"/>
        			<h:outputText value="Click to show low inventory: "  /><p:spacer /><p:commandButton action="#{inventoryBean.findLowInventory}" value="Show Low" update="medinv,inventoryId" process="@this"/>
        			<p:spacer height="2"/><p:spacer height="2"/><p:spacer height="2"/>
        			<h:outputText value="Click to show all inventory: "  /><p:spacer /><p:commandButton action="#{inventoryBean.findAllInventory}" value="Show All" update="medinv,inventoryId" process="@this"/>
    	</h:panelGrid>
    </p:panel>
    </div>
    <br />
    <div id="block1" align="center" style="width : 800px; font-size: 10pt" >	
    <p:panel>
        	<p:dataTable id="medinv" var="medinvs" value="#{inventoryBean.inventoryList}" style="text-align : center" paginator="true" rows="10">  
  
        		<p:column headerText="Medication Id" style="width:10%">  
            		<h:outputText value="#{medinvs.medication.medicationId}" />  
        		</p:column>  
  
        		<p:column headerText="Generic Name" style="width:40%">  
            		<h:outputText value="#{medinvs.medication.genericName}" /> 
    	    	</p:column>  
  	
        		<p:column headerText="Available Quantity" style="width:20%">  
            		<h:outputText value="#{medinvs.availableQuantity}" />  
        		</p:column>  
  
        		<p:column headerText="Reorder Quantity" style="width:5%">  
            		<h:outputText value="#{medinvs.reorderQuantity}" />  
        		</p:column>  
  
  				<p:column headerText="Buy price" style="width:10%">  
            		<h:outputText value="#{medinvs.costPrice}" />  
        		</p:column> 
        		 
        		<p:column headerText="Ordered?" style="width:5%">  
            		<h:outputText value="#{medinvs.orderStatus}" />  
        		</p:column> 
        		
        		<p:column style="width:20%; text-align : center">  
                	<h:commandButton id="createButton" action="#{inventoryBean.createInventoryOrder}" value="Order" rendered="#{inventoryBean.action == 'order'}">  
                	<f:ajax execute="createButton" />
                	<f:setPropertyActionListener value="#{medinvs}" target="#{inventoryBean.medicationInventory}" /> 
    				<f:param name="medicationId" value="#{medinvs.medication.medicationId}" />
    				<f:param name="action" value="#{inventoryBean.action}" />
            		</h:commandButton>   
            		<h:commandButton id="viewButton" action="#{inventoryBean.view}" value="View" rendered="#{inventoryBean.action == 'find'}" >  
                	<f:ajax execute="viewButton"  />
                	<f:setPropertyActionListener value="#{medinvs}" target="#{inventoryBean.medicationInventory}" /> 
    				<f:param name="medicationId" value="#{medinvs.medication.medicationId}" />
    				<f:param name="action" value="#{inventoryBean.action}" />
            		</h:commandButton> 
       	 		</p:column>  
    	</p:dataTable>  
        	<h:commandButton id="allButton" value="Order All" action="#{inventoryBean.orderAll}" rendered="#{inventoryBean.showOrderAll}">
        		<f:ajax execute="allButton"  />
        	</h:commandButton>
    		</p:panel>
		</div>

		</h:form>

    </ui:define>
</ui:composition>
